package com.wiscamp.ninechapters.threeparties.email;

import com.wiscamp.ninechapters.common.rest.ResourceHelper;
import com.wiscamp.ninechapters.common.rest.RestResponse;
import com.wiscamp.ninechapters.threeparties.email.entities.dto.EmailDto;
import cube.ddd.adapter.BaseController;
import cube.ddd.aspect.HandleResourceException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.ws.rs.core.Context;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/ThreeParties")
@Tag(name = "第三方服务-邮件")
public class EmailContoller extends BaseController {

    private final EmailService emailService;

    public EmailContoller(EmailService emailService) {
        this.emailService = emailService;
    }

    @PostMapping("Email")
    @Operation(summary = "发送邮件")
    @HandleResourceException
    public RestResponse<Boolean> sendEmail(@Context HttpServletRequest request, @Context HttpServletResponse response,
                                           @RequestBody EmailDto dto) {
        var result = emailService.sendSimpleEmail(dto.getDeliver(), dto.getReceiver(), dto.getCarbonCopy(), dto.getSubject(), dto.getContent());
        return ResourceHelper.getOkResponse(request, response, result);
    }
}
